import { Component, Debounce } from '@/decorators';
import { Vue } from 'vue-class-component';
import { Swipe, SwipeItem, Button, Toast } from 'vant';
import request from '@/utils/request';

@Component({
  name: 'ProductDetail',
  render() {
    // ... render 代码
  }
})
export default class ProductDetail extends Vue {
  private product = {
    id: 1,
    title: '商品标题',
    price: '99.00',
    description: '商品详细描述...',
    images: [
      'https://fastly.jsdelivr.net/npm/@vant/assets/ipad.jpeg',
      'https://fastly.jsdelivr.net/npm/@vant/assets/cat.jpeg'
    ]
  };

  @Debounce(300)
  private async addToCart() {
    try {
      await request.post('/cart', { productId: this.product.id });
      Toast.success('添加成功');
      this.$router.push('/cart');
    } catch (error) {
      // 错误已在拦截器中处理
    }
  }

  @Debounce(300)
  private async buyNow() {
    try {
      await request.post('/orders', { productId: this.product.id });
      Toast.success('下单成功');
      this.$router.push('/orders');
    } catch (error) {
      // 错误已在拦截器中处理
    }
  }
}